package com.metaera.app.controller.presenter;

import com.metaera.app.controller.core.RequestPresenter;
import com.metaera.app.controller.view.core.INetworkRequestView;
import com.metaera.app.data.DataRepository;
import com.metaera.app.data.model.HomeNewsTypeResponse;
import com.metaera.app.data.network.ApiParam;
import com.metaera.app.data.rx.ResponseObserver;
import com.metaera.app.data.rx.SchedulersTransformer;

import java.util.List;

/**
 * 分类
 */
public class CategoryPresenter extends RequestPresenter<INetworkRequestView<List<HomeNewsTypeResponse>>> {

    private void categoryLists(int type){
        DataRepository.getInstance()
                .categoryLists(type)
                .compose(SchedulersTransformer.transformer())
                .subscribe(new ResponseObserver<>(
                                this,
                                mView,
                                response -> mView.successful(response.getData())
                        )
                );
    }

    public void home() {
        categoryLists(ApiParam.CATEGORY_TYPE_HOME);
    }

    public void flashNews(){
        categoryLists(ApiParam.CATEGORY_TYPE_FLASH_NEWS);
    }

    public void calendar(){
        categoryLists(ApiParam.CATEGORY_TYPE_CALENDAR);
    }
}
